package com.example.lastwork;

import android.util.Log;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class DBUtils {

    private final static String driver = "com.mysql.jdbc.Driver";
    private final static String url = "jdbc:mysql://192.168.43.179:3030/" +
            "android?allowMultiQueries=true&useUnicode=true&" +
            "characterEncoding=UTF-8&useSSL=false&" +
            "allowPublicKeyRetrieval=true&" +
            "autoReconnect=true&failOverReadOnly=false&serverTimezone=GMT";
    //192.168.43.179
//    jdbc:mysql://localhost:3306/citymanager?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
//    useUnicode=true&characterEncoding=UTF-8&useSSL=false
 //   autoReconnect=true&failOverReadOnly=false
//    seUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
    private final static String username = "root";
    private final static String password = "yangchenxi";

    Connection conn=null;
    Statement st=null;
    ResultSet rs=null;

    private static final String TAG = "wuyu";


    static {
        try {
            Log.i(TAG,"no");
            Class.forName(driver);
            Log.i(TAG,"no");
        } catch (ClassNotFoundException e) {
            System.out.println("加载驱动错误");
        }
    }


    //2. 获取连接
    public static Connection getConnect() throws Exception{

        return DriverManager.getConnection(url, username, password);
    }

    //3. 释放连接资源

    public static void release(Connection conn, Statement st, ResultSet rs) throws Exception {
        if (st != null) {
            st.close();
        }
        if (conn != null) {
            conn.close();
        }
        if(rs != null){
            rs.close();
        }
    }
}


